package io.renren.modules.bus.controller;

import java.util.*;
import io.renren.modules.sys.controller.AbstractController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.renren.modules.bus.entity.StoreEntity;
import io.renren.modules.bus.service.StoreService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;


/**
 * 店铺信息
 * @Author lililiang
 * @Date 2019-02-23 15:07:23
 */
@RestController
@Api(tags = "店铺信息")
@RequestMapping("/bus/store")
public class StoreController extends AbstractController{
    @Autowired
    private StoreService storeService;

    /**
     * 分页查询
     */
    @ApiOperation(value = "分页查询", response = StoreEntity.class)
    @GetMapping("/list")
    @RequiresPermissions("bus:store:list")
    public R list(
            @ApiParam(value = "id", required = false) @RequestParam(required = false) Integer id,
                @ApiParam(value = "店铺名称", required = false) @RequestParam(required = false) String storeName,
                @ApiParam(value = "店铺地址", required = false) @RequestParam(required = false) String address,
                @ApiParam(value = "备注", required = false) @RequestParam(required = false) String remark,
                @ApiParam(value = "创建时间", required = false) @RequestParam(required = false) Date createTime,
                @ApiParam(value = "状态，1有效，0无效，-1删除", required = false) @RequestParam(required = false) Integer status
        ){
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        params.put("storeName", storeName);
        params.put("address", address);
        params.put("remark", remark);
        params.put("createTime", createTime);
        params.put("status", status);
        PageUtils page = storeService.list4Page(params);
        return R.ok().put("page", page);
    }

    /**
     * 列表查询
     */
    @ApiOperation(value = "列表查询", response = StoreEntity.class)
    @GetMapping("/listByCondition")
    @RequiresPermissions("bus:store:list")
    public R listByCondition(
            @ApiParam(value = "id", required = false) @RequestParam(required = false) Integer id,
                @ApiParam(value = "店铺名称", required = false) @RequestParam(required = false) String storeName,
                @ApiParam(value = "店铺地址", required = false) @RequestParam(required = false) String address,
                @ApiParam(value = "备注", required = false) @RequestParam(required = false) String remark,
                @ApiParam(value = "创建时间", required = false) @RequestParam(required = false) Date createTime,
                @ApiParam(value = "状态，1有效，0无效，-1删除", required = false) @RequestParam(required = false) Integer status
        ){
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        params.put("storeName", storeName);
        params.put("address", address);
        params.put("remark", remark);
        params.put("createTime", createTime);
        params.put("status", status);
        List<StoreEntity> list = storeService.listByCondition(params);
        return R.ok().put("list", list);
    }

    /**
     * 查询详情
     */
    @ApiOperation(value = "查询详情", response = StoreEntity.class)
    @GetMapping("/info/{id}")
    @RequiresPermissions("bus:store:info")
    public R info(@PathVariable("id") Integer id){
        StoreEntity store = storeService.selectById(id);
        return R.ok().put("store", store);
    }

    /**
     * 新增保存
     */
    @ApiOperation(value = "新增保存", response = R.class)
    @PostMapping("/save")
    @RequiresPermissions("bus:store:save")
    public R save(@RequestBody StoreEntity entity){
        storeService.insert(entity);
        return R.ok();
    }

    /**
     * 修改保存
     */
    @ApiOperation(value = "修改保存", response = R.class)
    @PostMapping("/update")
    @RequiresPermissions("bus:store:update")
    public R update(@RequestBody StoreEntity entity){
		storeService.updateById(entity);
        return R.ok();
    }

    /**
     * 批量逻辑删除
     */
    @ApiOperation(value = "批量逻辑删除", response = R.class)
    @PostMapping("/delete")
    @RequiresPermissions("bus:store:delete")
    public R delete(@RequestBody Integer[] ids){
		storeService.deleteLogic(Arrays.asList(ids));
        return R.ok();
    }

}
